<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>对特定对象调用用户方法（已废弃）</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.call-user-method-array.html">call_user_method_array</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.class-alias.html">class_alias</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.call-user-method" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">call_user_method</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">call_user_method</span> &mdash; <span class="dc-title">
   对特定对象调用用户方法（已废弃）
  </span></p>

 </div>
 <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.call-user-method-unknown-unknown-seealsq">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>call_user_method</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$method_name</code></span>
   , <span class="methodparam"><span class="type">object</span> <code class="parameter reference">&$obj</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$parameter</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></span>
  ]] )</div>

  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    <span class="function"><strong>call_user_method()</strong></span> 
    函数从 PHP 4.1.0 开始已经停用，使用 <span class="function"><a href="function.call-user-func.html" class="function">call_user_func()</a></span> 
    函数和 <em>array(&amp;$obj, &quot;method_name&quot;)</em>
    语法代替。
   </p>
  </div>
  <p class="para">
   从用户定义的 <em><code class="parameter">obj</code></em> 
   对象中调用 <em><code class="parameter">method_name</code></em>
   指的方法。下边是用法示例，我们定义了一个类，接着创建了一个对象实例，然后使用
   <span class="function"><strong>call_user_method()</strong></span> 间接调用它的
   <var class="varname"><var class="varname">print_info</var></var> 方法。
  </p>
  <p class="para">
   <div class="informalexample">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Country&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span style="color: #0000BB">$NAME</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span style="color: #0000BB">$TLD</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">Country</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$tld</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">NAME&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">TLD&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tld</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">print_info</span><span style="color: #007700">(</span><span style="color: #0000BB">$prestr</span><span style="color: #007700">=</span><span style="color: #DD0000">""</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$prestr&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"Country:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">NAME&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$prestr&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"Top&nbsp;Level&nbsp;Domain:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">TLD&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$cntry&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Country</span><span style="color: #007700">(</span><span style="color: #DD0000">"Peru"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"pe"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"*&nbsp;Calling&nbsp;the&nbsp;object&nbsp;method&nbsp;directly\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$cntry</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">print_info</span><span style="color: #007700">();<br /><br />echo&nbsp;</span><span style="color: #DD0000">"\n*&nbsp;Calling&nbsp;the&nbsp;same&nbsp;method&nbsp;indirectly\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">call_user_method</span><span style="color: #007700">(</span><span style="color: #DD0000">"print_info"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$cntry</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\t"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="simpara">
   参见 <span class="function"><a href="function.call-user-func-array.html" class="function">call_user_func_array()</a></span> 和
   <span class="function"><a href="function.call-user-func.html" class="function">call_user_func()</a></span>。
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.call-user-method-array.html">call_user_method_array</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.class-alias.html">class_alias</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
